(function(window) {
	var vm;
	var id = "";
	var devSN = "";
	var userName = "";
//	var commonLocale = dataManager.getLocale();

	function PulldownRefresh(isPulldownRefresh) {
		var self = this;
		isPulldownRefresh = isPulldownRefresh === undefined ? true : isPulldownRefresh;
		setTimeout(function() {
			isPulldownRefresh && self.endPullDownToRefresh();
		}, 2000);
		v3DevMonitor.getCpuinfo(devSN, function(code, data) {
			if(data.errCode === 0) {
				vm.cpuinfo = data.cpuInfo.cpuRatio;
			} else {

			}
		})
		v3DevMonitor.getMemoryinfo(devSN, function(code, data) {
			if(data.errCode === 0) {
				vm.memorinfo = data.memoryInfo.memoryRatio;
				//				Vue.set(vm.memorinfo, 1, data.memoryInfo.highestMemoryRatio);
			} else {

			}
		})
		v3DevMonitor.getDevspeed(devSN, function(code, data) {
			if(data.errCode === 0) {
				vm.devspeed = data.speed.speed_up;
			} else {

			}
		})
		v3AceAuthdata.getDeviceInfo(id, function(code, data) {
			if(code === 0) {
				vm.deviceInfoOne = data.shopName;
				vm.deviceInfoTwo = data.customTypeStr;
				vm.deviceInfoThree = data.devAlias;
				vm.deviceInfoFor = data.devSn;
				vm.deviceInfoFive = data.powerOnDurationStr;
				vm.deviceInfoSix = data.onlineDurationStr;
				vm.deviceInfoSeven = data.softVer
			}
		})
		v3StaMonitor.getTerminalCount(devSN, function(code, data) {
			if(code === 0) {
				vm.terminalTotal = data.client_statistic.band_2_4g + data.client_statistic.band_5g;
			}
		});
	}
	
	function directRestart(){
		mui.confirm('确定要直接重启吗？', '提示', function(e){
			if (e.index == 1) {
				v3BaseReset.deviceOperation(devSN,0,function(code,data){
					if(code === 0){
						if(data.retCode === 0){
							mui.toast('保存并重启成功');
						}else if(data.retCode === 1){ 
							mui.toast('保存配置失败'); 
						}else if(data.retCode === 2){  
							mui.toast('重启设备失败');
						}else if(data.retCode === 3){ 
							mui.toast('主链接没有找到');
						}else if(data.retCode === 4){
							mui.toast('权限不足');
						}else{
							mui.toast('其他错误');
						}
					}else{
						mui.toast('操作失败');
					}
		        });
			}
		})
	}
	
	function mainLinkReconnect(){
		mui.confirm('确定要重置主链接？', '提示', function(e){
			if (e.index == 1) {
				v3BaseReset.mainLinkReconnect(devSN,function(code,data){
					if(code === 0){
						if(data.retCode === 0){
							mui.toast('主链接重连成功');
						}else{
							mui.toast('主链接重连失败');
						}
					}else{
						mui.toast('操作失败');
					}
		        });
			}
		})
	}

	function mounted() {
		vm = this;

		$.plusReady(function() {
			id = plus.webview.currentWebview().value.id;
			devSN = $.util.getDevSN();
			userName = dataManager.getUserName();
			PulldownRefresh(false);
			$('.mui-scroll-wrapper').scroll({
				indicators: true, //是否显示滚动条
				bounce: false,
				deceleration: 0.0005
			});

			$("#manager-scroll").pullToRefresh({
				down: {
					//					callback: managerPagePulldownRefresh
				}
			});
		});
	}

	window.device = {
		mounted: mounted,
		data: {
			cpuinfo: 0,
			memorinfo: 0,
			devspeed: 0,
			deviceInfoOne: '',
			deviceInfoTwo: '',
			deviceInfoThree: '',
			deviceInfoFor: '',
			deviceInfoFive: '',
			deviceInfoSix: '',
			deviceInfoSeven: '',
			terminalTotal: 0,
			devName: "",
			devSN: ""
		},
		methods: {
			deviceConfiguration: function(){
				commonTool.openWindow('smallBie/config.html', 'mallBie/config.html');
			},
			diagnose: function(){
				commonTool.openWindow('smallBie/diagnose.html', 'mallBie/diagnose.html');
			},
			directRestart: directRestart,
			mainLinkReconnect: mainLinkReconnect,
			cpuDetail: function(){
				commonTool.openWindow('smallBie/cpuDetail.html', 'mallBie/cpuDetail.html');
			},
			merrayDetail: function(){
				commonTool.openWindow('smallBie/merrayDetail.html', 'mallBie/merrayDetail.html');
			},
			flowDetail: function(){
				commonTool.openWindow('smallBie/flowDetail.html', 'mallBie/flowDetail.html');
			}
		}
	};
})(window);